﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Antlr.Runtime;
using Antlr.Runtime.Tree;

namespace ObjCConverter
  {
  class Program
    {
    static void Main( string[] args )
      {
      processFile( "example2.m" );
      }

    private static void processFile( String filePath )
      {
      CommonTree ast = getAST( new StreamReader( filePath ) );
      Console.Out.WriteLine( ast.ToStringTree() ); // for debugging
      // processAST(ast);
      }

    private static CommonTree getAST( StreamReader reader )
      {
      ObjectiveC2ansiParser tokenParser = new ObjectiveC2ansiParser( getTokenStream( reader ) );
      ObjectiveC2ansiParser.translation_unit_return parserResult =
          tokenParser.translation_unit(); // start rule method
      reader.Close();
      return (CommonTree)parserResult.Tree;
      }

    private static CommonTokenStream getTokenStream( StreamReader reader )
      {
      ObjectiveC2ansiLexer lexer = new ObjectiveC2ansiLexer( new ANTLRReaderStream( reader ) );
      return new CommonTokenStream( lexer );
      }
    }
  }
